package com.mail.controller;

import com.mail.exception.MyException;
import com.sun.mail.smtp.SMTPAddressFailedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mail.service.IEmailService;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 刘浩然
 * @Date: 2021/5/8 11:00
 */
@Controller
public class MailController {
@Autowired
IEmailService mail;
@RequestMapping("/send")
public String mail(HttpServletRequest request) throws Exception {
    String number = "1727481162@qq.com";
    String title = "hellowrold";
    String content = "hellowrold";
    try{
        mail.sendMail(number,title,content);//发送邮件
    }catch (MailSendException e){
//        System.out.println(e);
            throw new MyException("发送失败,原因可能是 邮箱地址不存在");
    }
    request.getSession().setAttribute("qq",number);
    request.getSession().setAttribute("title",title);
    request.getSession().setAttribute("content",content);
    return "hello";
}
}
